package com.ruoyi.project.system.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.system.domain.Dan;
import com.ruoyi.project.system.service.IDanService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 运输单Controller
 * 
 * @author ruoyi
 * @date 2021-04-26
 */
@RestController
@RequestMapping("/system/dan")
public class DanController extends BaseController
{
    @Autowired
    private IDanService danService;

    /**
     * 查询运输单列表
     */
    @PreAuthorize("@ss.hasPermi('system:dan:list')")
    @GetMapping("/list")
    public TableDataInfo list(Dan dan)
    {
        startPage();
        List<Dan> list = danService.selectDanList(dan);
        return getDataTable(list);
    }

    /**
     * 导出运输单列表
     */
    @PreAuthorize("@ss.hasPermi('system:dan:export')")
    @Log(title = "运输单", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(Dan dan)
    {
        List<Dan> list = danService.selectDanList(dan);
        ExcelUtil<Dan> util = new ExcelUtil<Dan>(Dan.class);
        return util.exportExcel(list, "dan");
    }

    /**
     * 获取运输单详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:dan:query')")
    @GetMapping(value = "/{publishId}")
    public AjaxResult getInfo(@PathVariable("publishId") String publishId)
    {
        return AjaxResult.success(danService.selectDanById(publishId));
    }

    /**
     * 新增运输单
     */
    @PreAuthorize("@ss.hasPermi('system:dan:add')")
    @Log(title = "运输单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Dan dan)
    {
        return toAjax(danService.insertDan(dan));
    }

    /**
     * 修改运输单
     */
    @PreAuthorize("@ss.hasPermi('system:dan:edit')")
    @Log(title = "运输单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Dan dan)
    {
        return toAjax(danService.updateDan(dan));
    }

    /**
     * 删除运输单
     */
    @PreAuthorize("@ss.hasPermi('system:dan:remove')")
    @Log(title = "运输单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{publishIds}")
    public AjaxResult remove(@PathVariable String[] publishIds)
    {
        return toAjax(danService.deleteDanByIds(publishIds));
    }
}
